import { _BasicDataSource } from "../../_BasicDataSource"
import { uuid } from '../../util'

import { BaseEntity } from "../Entitys/BaseEntity";
import { Radar } from '../Entitys/_Radar'


class RadarEntity {
    constructor(Platform, parent) {
        this.id = 'RadarEntity_' + Platform.id;
        this.EntityTypeName = 'RadarEntity';
        this.parent = parent;
        this.Platform = Platform;

        // 基础平台类型
        this.BaseEntity = new BaseEntity({});
        this.BaseEntity.CesiumPosition = Platform.BaseEntity.CesiumPosition;
        this.Radar = new Radar(this.BaseEntity.Entity, Platform.options, parent.options);

        this.Radar.changeSenceType(parent._SenceMode);

        this._changeSceneMode = (type) => {
            this.Radar.changeSenceType(type);
        }
        this.parent.on('changeSceneMode', this._changeSceneMode);

        // 输出用于图层加载的对象
        this.Entity = this.BaseEntity.Entity;
        this.Entity.position.setValue(this.BaseEntity.CesiumPosition);
        this.Platform.addLink(this);
    }
    setPosition() {
        this.BaseEntity.CesiumPosition = this.Platform.BaseEntity.CesiumPosition;
        this.Entity.position.setValue(this.BaseEntity.CesiumPosition);
    }
    destroy() {
        this.parent.off('changeSceneMode', this._changeSceneMode);
        this.Platform.removeLink(this);
    }
    set Color(value) {
        this.Radar.Color = value;
    }
    get Color() {
        return this.Radar.Color
    }
}



class RadarDataSource extends _BasicDataSource {
    constructor(parent, options, parentDataSource) {
        super(uuid(), parent, options);
        this.parentDataSource = parentDataSource;
        this.options = options || {};
        this.color = this.options.color;
    }
    add(id) {
        var platform = this.parentDataSource.GetMappingById(id);
        const _Radar = new RadarEntity(platform, this);
        this._Mapping[_Radar.id] = _Radar;
        this._Entities.add(_Radar.Entity);
        return _Radar;
    }
    set Color(value) {
        this.EachMapping((item) => {
            item.Color = value;
        })
    }
    get Color() {
        return this.options.color
    }
}

export {
    RadarEntity,
    RadarDataSource
}
